#include <cstdint>
#include <iostream>

enum AlarmFlag {
    kNotNeedAlarm = 0,
    kNeedAlarm    = 1,
    kErrorCode    = 2,
};

enum AlarmFlagAsInt : int {
    kNotNeedAlarmAsInt = 0,
    kNeedAlarmAsInt    = 1,
    kErrorCodeAsInt    = 2,
};

enum class AlarmFlagAsClass : int {
    kNotNeedAlarmAsClass = 0,
    kNeedAlarmAsClass    = 1,
    kErrorCodeAsClass    = 2,
};

void default_enum() {
    AlarmFlag flag = static_cast<AlarmFlag>(0);  // 不允许隐式转换
    flag           = kNeedAlarm;
    int temp       = flag;  // 允许隐式转换为int类型
    (void)temp;
    std::cout << flag << std::endl;
}

void enum_as_int() {
    AlarmFlagAsInt flag = static_cast<AlarmFlagAsInt>(0);  // 不允许隐式转换
    flag                = kNeedAlarmAsInt;
    int     temp        = flag;  // 允许隐式转换为int类型
    int16_t temp2       = flag;  // 允许隐式转换为short类型
    std::cout << flag << std::endl;

    (void)temp;
    (void)temp2;
}

void enum_as_class() {
    AlarmFlagAsClass flag = static_cast<AlarmFlagAsClass>(0);  // 不允许隐式转换
    // flag = kNeedAlarmAsClass;   // 必须携带枚举类型名
    flag = AlarmFlagAsClass::kNeedAlarmAsClass;
    // int temp = flag;                 // 不允许隐式转换
    // std::cout << flag << std::endl;  // 不允许隐式转换为int类型使用

    (void)flag;
}
